<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();

$target_ext = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION);
$filename=pathinfo($_FILES["file"]["name"], PATHINFO_FILENAME).".".$target_ext;
$uploadOk = 1; // 初始化上传状态
require_once './db/conn.php';
$data=array('cod'=>'','id'=>'','value'=>'','text'=>'');
// 检查文件类型
if ($target_ext != "zip" && $target_ext != "rar" && $target_ext != "7z") {
	$data['text'] = "只允许上传zip、rar、7z格式的文件。";
	$uploadOk = 0;
}else if($_FILES["file"]["size"] > 50000000){
	$data['text'] = "上传文件太大了。";
	// 检查文件大小
	$uploadOk = 0;
}
// 如果文件通过检查，则将其保存到服务器
if ($uploadOk == 0) {
	$data['cod'] = 1;
	echo json_encode($data);
} else {
	for ($tname = 0; file_exists("../../data/upload/more/" . $tname . "." . $target_ext) == true; $tname++) {
	}
	move_uploaded_file($_FILES["file"]["tmp_name"], "../../data/upload/more/" . $tname . "." . $target_ext);
	$data['value']= "/data/upload/more/" . $tname . "." . $target_ext;
	$database->insert("more_file",["name"=>$filename,"file_url"=>$data['value'],"file_time"=>time(),"file_tmp"=>"是"]);
	$id = $database->select("more_fild",["id"],["name"=>$tname]);
	$data['id'] = $database->id();
	$data['cod'] = 0;
	$data['name'] = $filename;
	echo json_encode($data);
}
?>